package com.wfy.common.entity;


import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableLogic;
import com.baomidou.mybatisplus.enums.IdType;
import com.wfy.common.security.shiro.utils.ShiroHolder;
import com.wfy.modules.sys.secutiry.PrincipalUser;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: wangxindong
 * @date: 2018/5/18-20:05
 */
public abstract class BaseEntity<T> extends Model implements Serializable {

    // ================================================================
    // Constants
    // ================================================================

    private static final long serialVersionUID = 1L;

    // ================================================================
    // Fields
    // ================================================================

    @TableId(value = "id", type = IdType.UUID)
    protected String id;

    @TableField(value = "create_by")
    protected String createBy;

    @TableField(value = "create_date")
    protected Date createDate;

    @TableField(value = "update_by")
    protected String updateBy;

    @TableField(value = "update_date")
    protected Date updateDate;

    @TableField(value = "remarks")
    protected String remarks;

    @TableField(value = "del_flag")
    @TableLogic
    protected int delFlag;

    /**
     * sql查询条件扩展字段
     */
    @TableField(exist = false)
    private Map<String, Object> sqlMap;

    // ================================================================
    // Constructors
    // ================================================================

    public BaseEntity() {

    }

    public BaseEntity(String id) {
        this.id = id;
    }

    // ================================================================
    // Methods from/for super Interfaces or SuperClass
    // ================================================================

    @Override
    protected Serializable pkVal() {
        return id;
    }

    // ================================================================
    // Public or Protected Methods
    // ================================================================

    public void preUpdate() {
        PrincipalUser user = ShiroHolder.getUser();
        if (null != user) {
            this.updateBy = user.getId();
        }
        this.updateDate = new Date();
    }

    public void preInsert() {
        PrincipalUser user = ShiroHolder.getUser();
        this.createDate = new Date();
        if (null != user) {
            this.createBy = user.getId();
        }
    }


    // ================================================================
    // Getter & Setter
    // ================================================================

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public int getDelFlag() {
        return delFlag;
    }

    public void setDelFlag(int delFlag) {
        this.delFlag = delFlag;
    }

    public Map<String, Object> getSqlMap() {
        return sqlMap;
    }

    public void setSqlMap(Map<String, Object> sqlMap) {
        this.sqlMap = sqlMap;
    }

    // ================================================================
    // Private Methods
    // ================================================================


    // ================================================================
    // Inner or Anonymous Class
    // ================================================================

    // ================================================================
    // Test Methods
    // ================================================================

}
